const path = require('path');
const Koa = require('koa');
const { koaBody } = require('koa-body');
const KoaStatic = require('koa-static');
const KoaParameter = require('koa-parameter');
const router = require('../router');
const errorHandler = require('./errorHandler')
console.log('process.env.MYSQL_ADDRESS',process.env.MYSQL_ADDRESS)
const app = new Koa();
app.use(koaBody({
  multipart: true,
  formidable:{
    uploadDir: path.join(__dirname, '../upload'),
    keepExtensions: true
  }
}))
app.use(KoaStatic(path.join(__dirname, '../upload')))
app.use(KoaParameter(app))
app.use(router.routes()).use(router.allowedMethods())

// 统一错误处理
app.on('error', errorHandler)

module.exports = app